package com.joker.product.controller;

import com.joker.common.core.domain.Result;
import com.joker.common.core.utils.poi.ExcelUtil;
import com.joker.common.core.web.controller.BaseController;
import com.joker.common.log.annotation.Log;
import com.joker.common.log.enums.BusinessType;
import com.joker.common.security.annotation.RequiresPermissions;
import com.joker.product.domain.Merchant;
import com.joker.product.domain.PmsSkuInfo;
import com.joker.product.domain.vo.SkuWarningVO;
import com.joker.product.query.PmsSkuQuery;
import com.joker.product.service.IPmsSkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * sku信息Controller
 *
 * @author jorker
 * @date 2024-12-24
 */
@RestController
@RequestMapping("/skuInfo")
public class PmsSkuInfoController extends BaseController
{
    @Autowired
    private IPmsSkuInfoService pmsSkuInfoService;

    /**
     * 查询sku信息列表
     */
    @GetMapping("/warningList")
    public Result list(PmsSkuQuery query)
    {
        startPage();
        List<SkuWarningVO> list = pmsSkuInfoService.getWarningList(query);
        return getDataTable(list);
    }


    /**
     * 获取sku信息详细信息
     */
    @RequiresPermissions("product:skuInfo:query")
    @GetMapping(value = "/{skuId}")
    public Result<PmsSkuInfo> getInfo(@PathVariable("skuId") Long skuId)
    {
        return success(pmsSkuInfoService.selectPmsSkuInfoBySkuId(skuId));
    }

    /**
     * 获取sku信息详细信息
     */
    @GetMapping(value = "/getMerchantBySkuId/{skuId}")
    public Result<Merchant> getMerchantBySkuId(@PathVariable("skuId") Long skuId)
    {
        return success(pmsSkuInfoService.selectMerchantBySkuId(skuId));
    }

    /**
     * 获取sku信息详细信息
     */
    @GetMapping(value = "/getSaleAttrBySkuId/{skuId}")
    public Result<List<String>> getSaleAttrBySkuId(@PathVariable("skuId") Long skuId)
    {
        return success(pmsSkuInfoService.selectMerchantBySkuId(skuId));
    }

    /**
     * 新增sku信息
     */
    @RequiresPermissions("product:skuInfo:add")
    @Log(title = "sku信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody PmsSkuInfo pmsSkuInfo)
    {
        return toAjax(pmsSkuInfoService.insertPmsSkuInfo(pmsSkuInfo));
    }

    /**
     * 修改sku信息
     */
    @RequiresPermissions("product:skuInfo:edit")
    @Log(title = "sku信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody PmsSkuInfo pmsSkuInfo)
    {
        return toAjax(pmsSkuInfoService.updatePmsSkuInfo(pmsSkuInfo));
    }

    /**
     * 删除sku信息
     */
    @RequiresPermissions("product:skuInfo:remove")
    @Log(title = "sku信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{skuIds}")
    public Result remove(@PathVariable Long[] skuIds)
    {
        return toAjax(pmsSkuInfoService.deletePmsSkuInfoBySkuIds(skuIds));
    }

}
